$(function() {
    var module = {};
    var tools = Tools();
    var insHt=tools.investHt;
    module.init=function () {
        tools.getUserInfo();
        $('.COMPLETED').on('click',function () {
            $('#investA').show();
            module.initData('COMPLETED','pager',false);
            $('.ING_h').removeClass('curr');
            $('.COMPLETED_h').addClass('curr');
        });
        $('.ING').on('click',function () {
            $('#investA').show();
            module.initData('ING','pager',false);
            $('.COMPLETED_h').removeClass('curr');
            $('.ING_h').addClass('curr');
        });
        module.initData('ING','pager','true');
        tools.isOpenAccount(); 
    };

    module.initData=function (types,pages,tag) {
        //初始化  投资标  进行中
        var searchP={};
        $('#'+pages).sjAjaxPager({
            url: ajaxjsURL+tools.apiURL.queryInvestPage,
            pageSize: 10,
            type :'GET',
            orderField:'gmtCreated',
            orderDirection:'desc',
            searchParam: {
                type : 1,
                status:types,
                pageStart:tag
            },
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            beforeSend: function(xhr) {

            },
            success: function (data1) {
                var content = data1.data.data;
                var clickId,alertId;
                var list = '',
                    page = '';
                if(content && content.length){
                    list += $.map(content,function(value,len){
                        var orderList='';
                        var orders='';
                        for(var num=0;num<value.orderInterestList.length;num++){
                            var orderD=value.orderInterestList[num];
                            var orderStatus='';
                            if(orderD.status==0){
                                orderStatus='未还';
                            }else{
                                orderStatus='已还';
                            }
                           orders+='<tr><td>'+orderD.endDate+'</td> <td>'+orderD.payablePrincipal+'元</td> <td>'+orderD.days+'天</td> <td>'+orderD.payableInterest+'元</td> <td>'+orderStatus+'</td> </tr>'

                        }
                         orderList='<div id="alertFuxiText'+value.debtId+ '" class="disNone"><div class="fuxiAlertClass"> <div class="fuxiP"> 投资本金: <em> '+value.investAmount+' 元</em>预期年化：<em>'+value.annualRate+'%</em>计息天数:<em>'+value.duration+'天</em>总收益：<em>'+value.payableInterest+'元</em> </div> <div class="fuxiTable"> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th>回报时间</th> <th>支付本金</th> <th>支付天数</th> <th>支付利息</th> <th>支付状态</th> </tr> </thead> <tbody>'+orders+'</tbody></table> </div> </div> </div>';

                        return '<tr><td><a href="/product/detail/'+value.debtId+'">'+value.debtTitle+'</a></td><td>'+value.annualRate.toFixed(2)+'%</td><td>'+value.investAmount.toFixed(2)+'</td><td>'+value.startDate+'</td><td>'+value.endDate+'</td><td><em class="fontGreen">'+value.payableInterest+'元</em></td><td><a href="javascript:;" class="two_tbl c'+value.debtId+ '"  >付息表</a><a href="'+insHt+value.orderNo+'" target="_blank" class="two_tbl contract">合同</a>'+orderList+'</td></tr>';

                 }).join('');
                    $('#pager').show();
                }else{
                    list += '<tr class="noList"><td colspan="7" align="center" style="text-align: center">暂无记录</tr>';
                     $('#pager').hide();
                }
                $('.investList tbody').empty().append(list);
                clickId='c';

                $.map(content,function(value,len){
                    $('.'+clickId+value.debtId).on('click',function(){
                        var textContent=$("#alertFuxiText"+value.debtId).html();
                        art.dialog({
                            id:'fuxi',
                            title:'还本付息表',
                            lock: true,
                            content: textContent,
                            left: 585,
                            top: 71,
                            width: 730,
                            zIndex: 1988,
                            position: 'absolute'

                        });
                    });
              /*      $(document).on("click", '.ht'+value.orderNo+ '', function () {
                        tools.doGet(ajaxjsURL + tools.apiURL.contractView,{orderNumber:value.orderNo},function (data) {
                            console.log('ddddddddd',data)
                        } );

                    });*/
                })

            },
            complete: function () {
            }
        });
    };
 

    module.init();
});